package com.lin.blog.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 
 * </p>
 *
 * @author lin
 * @since 2020-03-08
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value="Category对象", description="")
public class Category implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "分类ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @NotEmpty(message = "分类名不能为空")
    @ApiModelProperty(value = "分类名")
    private String categoryName;

    @ApiModelProperty(value = "分类描述")
    private String categoryDesc;

    @ApiModelProperty(value = "父分类ID")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;

    /**
     * TableField 只该字段不属于数据库
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "子列表")
    private List<Category> children;

    public Category(Long id, String categoryName, String categoryDesc, Long parentId) {
        this.id = id;
        this.categoryName = categoryName;
        this.categoryDesc = categoryDesc;
        this.parentId = parentId;
    }

    @Override
    public String toString() {
        return "Category{" +
                "id=" + id +
                ", categoryName='" + categoryName + '\'' +
                ", categoryDesc='" + categoryDesc + '\'' +
                ", parentId=" + parentId +
                ", children=" + children +
                '}';
    }
}
